<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE );
/**
 * 获取设备状态接口
 *
 * 
 */
 
use Workerman\Worker;
use Workerman\Mysql;

 class mod_settings_department_headquarters{
	
	public function entry($param){
		return $this->do_mod_settings_department_headquarters($param);
	}

		
	/** 
	* do_mod_settings_user  
	* 获取批次等级分布
	* 
	* @access private 
	* @param $param batch
	* @since 1.0 
	* @return array(errcode,errmsg,rtv) 
	*/
	private function do_mod_settings_department_headquarters($param){
		$action = $param["action"];
		if(empty($action) || $action==""){
			$sql = "select * from hf_mes_department_headquarters;";
			$dp=sql_queryIdx($sql);
			//$obj = "{\"data\": " . json_encode($dp) . "}" ;
			$obj = new stdClass();
            $obj-> data = $dp;
		}


		if($action == "add"){
			$name = $_POST["name"];
			$code = $_POST["code"];
			$note = $_POST["note"];
			sql_insert("hf_mes_department_headquarters",array('name'=>$name,'code'=>$code,'note'=>$note));
			$obj = "done";
		}

		if($action == "edit"){
			$id = $_POST["id"];
			$name = $_POST["name"];
			$code = $_POST["code"];
			$note = $_POST["note"];
			sql_update("hf_mes_department_headquarters", array('name'=>$name,'code'=>$code,'note'=>$note), array('id'=>$id));
			$obj =  "done";
		}

		if($action == "delete"){
			$id = $_POST["id"];
			sql_delete("hf_mes_department_headquarters", array('id'=>$id));
			$obj =  "done";
		}

		if($action=="check_name"){
			$id = $_POST['id'];
			$data = $_POST['data'];
			
			$obj =  checkUniqueValue_jsValidate("hf_mes_department_headquarters", $id, $data, "name");

		}

		if($action=="check_code"){
			$id = $_POST['id'];
			$data = $_POST['data'];
			
			$obj =  checkUniqueValue_jsValidate("hf_mes_department_headquarters", $id, $data, "code");

		}
		return array("errcode"=> 0,"errmsg"=>"","rtval"=>$obj);
	}


	/** 
	* create  
	* 通过 call_user_func 获得本class的实例
	* 
	* @access public 
	* @since 1.0 
	* @return object 本类的实例
	*/	
    public static function create(){  
        static $instance;
        if (!$instance){  
			$instance = new mod_settings_department_headquarters();  
        }
		return $instance;  
    }   
 }


